From 90ecd3c5808d0cf81f3463bf80d1cd5ac164bbda Mon Sep 17 00:00:00 2001 From: robertlipe Date: Sat, 23 Mar 2013 21:09:32 +0000 Subject: [PATCH] Move the URL link and text from C strings to QStrings. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4356 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/an1.cc | 6 +++--- gpsbabel/cet_util.cc | 7 +++++-- gpsbabel/cet_util.h | 2 +- gpsbabel/cst.cc | 4 ++++ gpsbabel/csv_util.cc | 4 ++-- gpsbabel/defs.h | 21 +++++++++------------ gpsbabel/gdb.cc | 14 +++++++------- gpsbabel/html.cc | 2 +- gpsbabel/kml.cc | 8 +++++--- gpsbabel/lmx.cc | 4 ++-- gpsbabel/mmo.cc | 4 ++-- gpsbabel/mtk_logger.cc | 2 +- gpsbabel/navicache.cc | 2 +- gpsbabel/tmpro.cc | 2 +- gpsbabel/vcf.cc | 2 +- gpsbabel/waypt.cc | 29 ++++++----------------------- 16 files changed, 51 insertions(+), 62 deletions(-) diff --git a/gpsbabel/an1.cc b/gpsbabel/an1.cc index 64b7adf6d..458afbba9 100644 --- a/gpsbabel/an1.cc +++ b/gpsbabel/an1.cc @@ -779,12 +779,12 @@ Write_One_AN1_Waypoint(const waypoint* wpt) } if (!nourl && wpt->hasLink()) { - int len = 7+strlen(wpt->url); + int len = 7 + wpt->url.length(); char* extra = (char*)xmalloc(len); - sprintf(extra, "{URL=%s}", wpt->url); + sprintf(extra, "{URL=%s}", wpt->url.toUtf8().data()); rec->name = xstrappend(rec->name, extra); xfree(extra); - rec->url = xstrdup(wpt->url); + rec->url = xstrdup(wpt->url.toUtf8().data()); } if (wpt->notes) { diff --git a/gpsbabel/cet_util.cc b/gpsbabel/cet_util.cc index 54b0e0898..b86d73f05 100644 --- a/gpsbabel/cet_util.cc +++ b/gpsbabel/cet_util.cc @@ -1021,8 +1021,11 @@ cet_convert_string(char* str) } const char * -cet_convert_string(QString str) { - return cet_convert_string(str.toUtf8().data()); +cet_convert_string(const QString& str) { + // FIXME: this is really weird. Since cet_convert_string wants to free + // its argument (!) we make a duplicate just to satisfy that kind of goofy + // requirement. + return cet_convert_string(xstrdup(str.toUtf8().data())); } /* cet_convert_waypt: internal used within cet_convert_strings process */ diff --git a/gpsbabel/cet_util.h b/gpsbabel/cet_util.h index e01a73ef4..bc2ea1466 100644 --- a/gpsbabel/cet_util.h +++ b/gpsbabel/cet_util.h @@ -109,7 +109,7 @@ int cet_gbfprintf(gbfile* stream, const cet_cs_vec_t* src_vec, const char* fmt, /* cet_convert_string: !!! ONLY VALID WITHIN 'cet_convert_strings' process !!! */ char* cet_convert_string(char* str); -const char* cet_convert_string(QString str); +const char* cet_convert_string(const QString& str); /* gpsbabel extensions */ diff --git a/gpsbabel/cst.cc b/gpsbabel/cst.cc index ffe89401a..7bdc32bbb 100644 --- a/gpsbabel/cst.cc +++ b/gpsbabel/cst.cc @@ -60,10 +60,14 @@ cst_add_wpt(const route_head* track, waypoint* wpt) if (wpt->shortname != NULL) { waypt_add(waypt_dupe(wpt)); +#if 0 if (wpt->url != NULL) { xfree(wpt->url); wpt->url = NULL; } +#else + wpt->url.clear(); +#endif if (temp_route == NULL) { temp_route = route_head_alloc(); diff --git a/gpsbabel/csv_util.cc b/gpsbabel/csv_util.cc index f7c9616a5..90456a4f9 100644 --- a/gpsbabel/csv_util.cc +++ b/gpsbabel/csv_util.cc @@ -1711,7 +1711,7 @@ xcsv_waypt_pr(const waypoint* wpt) off = strlen(xcsv_urlbase); } if (wpt->hasLink()) { - snprintf(buff + off, sizeof(buff) - off, fmp->printfc, wpt->url); + snprintf(buff + off, sizeof(buff) - off, fmp->printfc, wpt->url.toUtf8().data()); } else { strcpy(buff, (fmp->val && *fmp->val) ? fmp->val : "\"\""); } @@ -1719,7 +1719,7 @@ xcsv_waypt_pr(const waypoint* wpt) break; case XT_URL_LINK_TEXT: snprintf(buff, sizeof(buff), fmp->printfc, - (wpt->hasLinkText()) ? wpt->url_link_text : fmp->val); + (wpt->hasLinkText()) ? wpt->url_link_text.toUtf8().data() : fmp->val); break; case XT_ICON_DESCR: writebuff(buff, fmp->printfc, diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 5d23e9e8b..414e32882 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -371,13 +371,11 @@ fs_xml* fs_xml_alloc(long type); class url_link { public: url_link() : - url_next(NULL), - url(NULL), - url_link_text(NULL) + url_next(NULL) {} ; url_link* url_next; - char* url; - char* url_link_text; + QString url; + QString url_link_text; }; /* @@ -461,8 +459,6 @@ public: description(NULL), notes(NULL), url_next(NULL), - url(NULL), - url_link_text(NULL), #if NEWTIME // creation_time(QDateTime::fromTime_t(0)), #else @@ -537,10 +533,10 @@ public: * members must match struct url_link... */ url_link* url_next; - bool hasLink() const {return url && *url; } - bool hasLinkText() const {return url_link_text && *url_link_text; } - char* url; - char* url_link_text; + bool hasLink() const {return !url.isEmpty(); } + bool hasLinkText() const {return !url_link_text.isEmpty(); } + QString url; + QString url_link_text; wp_flags wpt_flags; QString icon_descr; @@ -688,7 +684,8 @@ void waypt_flush(queue*); void waypt_flush_all(void); unsigned int waypt_count(void); void set_waypt_count(unsigned int nc); -void waypt_add_url(waypoint* wpt, char* link, char* url_link_text); +void waypt_add_url(waypoint* wpt, const QString& link, + const QString& url_link_text); void free_gpx_extras(xml_tag* tag); void xcsv_setup_internal_style(const char* style_buf); void xcsv_read_internal_style(const char* style_buf); diff --git a/gpsbabel/gdb.cc b/gpsbabel/gdb.cc index 6a726651e..09038461d 100644 --- a/gpsbabel/gdb.cc +++ b/gpsbabel/gdb.cc @@ -620,8 +620,8 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) res->url = FREAD_CSTR; if (wpt_class != 0) { - res->description = res->url; - res->url = NULL; + res->description = xstrdup(res->url.toUtf8().data()); + res->url.clear(); } } else { // if (gdb_ver >= GDB_VER_3) int i, url_ct; @@ -1342,7 +1342,7 @@ write_waypoint( FWRITE(zbuf, 3); FWRITE(zbuf, 4); descr = (wpt_class < gt_waypt_class_map_point) ? - wpt->url : wpt->description; + wpt->url.toUtf8().data() : wpt->description; if ((descr != NULL) && (wpt_class >= gt_waypt_class_map_point) && \ (strcmp(descr, wpt->shortname) == 0)) { descr = NULL; @@ -1378,7 +1378,7 @@ write_waypoint( cnt++; } for (url_next = wpt->url_next; (url_next); url_next = url_next->url_next) - if (url_next->url) { + if (!url_next->url.isEmpty()) { cnt++; } FWRITE_i32(cnt); @@ -1386,8 +1386,8 @@ write_waypoint( FWRITE_CSTR(wpt->url); } for (url_next = wpt->url_next; (url_next); url_next = url_next->url_next) - if (url_next->url) { - FWRITE_CSTR(url_next->url); + if (!url_next->url.isEmpty()) { + FWRITE_CSTR(url_next->url.toUtf8().data()); } } @@ -1645,7 +1645,7 @@ write_waypoint_cb(const waypoint* refpt) if ((test != NULL) && (route_flag == 0)) { if ((str_not_equal(test->notes, refpt->notes)) || - (str_not_equal(test->url, refpt->url))) { + test->url.compare(refpt->url)) { test = NULL; } } diff --git a/gpsbabel/html.cc b/gpsbabel/html.cc index 27c192e0c..57c154fe7 100644 --- a/gpsbabel/html.cc +++ b/gpsbabel/html.cc @@ -110,7 +110,7 @@ html_disp(const waypoint* wpt) if (strcmp(wpt->description, wpt->shortname)) { if (wpt->hasLink()) { char* d = html_entitize(wpt->description); - gbfprintf(file_out, "%s", wpt->url, d); + gbfprintf(file_out, "%s", wpt->url.toUtf8().data(), d); xfree(d); } else { gbfprintf(file_out, "%s", wpt->description); diff --git a/gpsbabel/kml.cc b/gpsbabel/kml.cc index 35eae91ba..0a23fbd42 100644 --- a/gpsbabel/kml.cc +++ b/gpsbabel/kml.cc @@ -1390,7 +1390,7 @@ char* kml_geocache_get_logs(const waypoint* wpt) return r; } -static void kml_write_data_element(const char* name, const char* value) +static void kml_write_data_element(const char* name, const QString& value) { writer.writeStartElement("Data"); writer.writeAttribute("name", name); @@ -1557,8 +1557,10 @@ static void kml_waypt_pr(const waypoint* waypointp) if (waypointp->hasLink()) { writer.writeEmptyElement("snippet"); if (waypointp->hasLinkText()) { - char* odesc = xml_entitize(waypointp->url); - char* olink = xml_entitize(waypointp->url_link_text); + // FIXME(robertlipe): these call to xml_entitize are suspicios with + // new XML serializer. + char* odesc = xml_entitize(waypointp->url.toUtf8().data()); + char* olink = xml_entitize(waypointp->url_link_text.toUtf8().data()); writer.writeStartElement("description"); writer.writeCDATA(QString("%2").arg(odesc, olink)); writer.writeEndElement(); // Close description tag diff --git a/gpsbabel/lmx.cc b/gpsbabel/lmx.cc index 09573ab94..c46e50bc0 100644 --- a/gpsbabel/lmx.cc +++ b/gpsbabel/lmx.cc @@ -174,7 +174,7 @@ lmx_end_tag(int tag, int indent) } static void -lmx_write_xml(int tag, const char* data, int indent) +lmx_write_xml(int tag, const QString& data, int indent) { lmx_start_tag(tag, indent); @@ -182,7 +182,7 @@ lmx_write_xml(int tag, const char* data, int indent) gbfputc(0x03, ofd); // inline string follows gbfputcstr(data, ofd); } else { - char* tmp_ent = xml_entitize(data); + char* tmp_ent = xml_entitize(data.toUtf8().data()); gbfputs(tmp_ent, ofd); xfree(tmp_ent); } diff --git a/gpsbabel/mmo.cc b/gpsbabel/mmo.cc index c879d562b..761938f8e 100644 --- a/gpsbabel/mmo.cc +++ b/gpsbabel/mmo.cc @@ -1013,7 +1013,7 @@ mmo_finalize_rtept_cb(const waypoint* wptref) wpt->notes = xstrdup(wpt2->notes); } if (wpt2->hasLink()) { - wpt->notes = xstrdup(wpt2->url); + wpt->notes = xstrdup(wpt2->url.toUtf8().data()); } wpt->proximity = wpt2->proximity; @@ -1310,7 +1310,7 @@ mmo_write_wpt_cb(const waypoint* wpt) if (wpt->hasLink()) { str = xstrdup("_FILE_ "); - str = xstrappend(str, wpt->url); + str = xstrappend(str, wpt->url.toUtf8().data()); str = xstrappend(str, "\n"); } else { str = xstrdup(""); diff --git a/gpsbabel/mtk_logger.cc b/gpsbabel/mtk_logger.cc index 37e948485..f2bb214a4 100644 --- a/gpsbabel/mtk_logger.cc +++ b/gpsbabel/mtk_logger.cc @@ -141,7 +141,7 @@ enum { RCR, MILLISECOND, DISTANCE, -} DATA_TYPES; +} /* DATA_TYPES */; struct log_type { int id; diff --git a/gpsbabel/navicache.cc b/gpsbabel/navicache.cc index 1d9b9eaa4..848f999d7 100644 --- a/gpsbabel/navicache.cc +++ b/gpsbabel/navicache.cc @@ -129,7 +129,7 @@ nav_start(void* data, const XML_Char* xml_el, const XML_Char** xml_attr) id = atoi(ap[1]); xasprintf(&wpt_tmp->shortname, "N%05X", id); - xasprintf(&wpt_tmp->url, "%s%d", NC_URL, id); + wpt_tmp->url = QString(NC_URL) + QString::number(id); } else if (0 == strcmp(ap[0], "name")) { wpt_tmp->description = xstrdup(ap[1]); } else if (0 == strcmp(ap[0], "user_name")) { diff --git a/gpsbabel/tmpro.cc b/gpsbabel/tmpro.cc index 58911d0ff..df7d9f39d 100644 --- a/gpsbabel/tmpro.cc +++ b/gpsbabel/tmpro.cc @@ -220,7 +220,7 @@ tmpro_waypt_pr(const waypoint * wpt) wpt->altitude, colour, icon, - wpt->hasLink() ? wpt->url : "" + wpt->hasLink() ? wpt->url.toUtf8().data() : "" ); diff --git a/gpsbabel/vcf.cc b/gpsbabel/vcf.cc index b0e586684..7c503198d 100644 --- a/gpsbabel/vcf.cc +++ b/gpsbabel/vcf.cc @@ -105,7 +105,7 @@ vcf_disp(const waypoint *wpt) gbfprintf(file_out, "ADR:%c%d %06.3f %c%d %06.3f\n", wpt->latitude < 0 ? 'S' : 'N', abs(latint), 60.0 * (fabs(wpt->latitude) - latint), wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint)); if (wpt->hasLink()) { - gbfprintf(file_out, "URL:%s\n", wpt->url); + gbfprintf(file_out, "URL:%s\n", wpt->url.toUtf8().data()); } gbfprintf(file_out, "NOTE:"); diff --git a/gpsbabel/waypt.cc b/gpsbabel/waypt.cc index f02d2e9de..2f5b89dc5 100644 --- a/gpsbabel/waypt.cc +++ b/gpsbabel/waypt.cc @@ -64,17 +64,12 @@ waypt_dupe(const waypoint *wpt) if (wpt->notes) { tmp->notes = xstrdup(wpt->notes); } - if (wpt->url) { - tmp->url = xstrdup(wpt->url); - } - if (wpt->url_link_text) { - tmp->url_link_text = xstrdup(wpt->url_link_text); - } + + tmp->url = (wpt->url); + tmp->url_link_text = wpt->url_link_text; for (url_link* url_next = wpt->url_next; url_next; url_next = url_next->url_next) { - waypt_add_url(tmp, - (url_next->url) ? xstrdup(url_next->url) : NULL, - (url_next->url_link_text) ? xstrdup(url_next->url_link_text) : NULL); + waypt_add_url(tmp, url_next->url, url_next->url_link_text); } tmp->icon_descr = wpt->icon_descr; @@ -399,24 +394,12 @@ waypt_free(waypoint *wpt) if (wpt->notes) { xfree(wpt->notes); } - if (wpt->url) { - xfree(wpt->url); - } - if (wpt->url_link_text) { - xfree(wpt->url_link_text); - } if (wpt->url_next) { url_link *url_next; for (url_next = wpt->url_next; url_next;) { url_link *tonuke = url_next; - if (tonuke->url) { - xfree(tonuke->url); - } - if (tonuke->url_link_text) { - xfree(tonuke->url_link_text); - } url_next = tonuke->url_next; xfree(tonuke); } @@ -509,7 +492,7 @@ waypt_restore(signed int count, queue *head_bak) } void -waypt_add_url(waypoint *wpt, char *link, char *url_link_text) +waypt_add_url(waypoint *wpt, const QString& link, const QString& url_link_text) { if ((link == NULL) && (url_link_text == NULL)) { return; @@ -521,7 +504,7 @@ waypt_add_url(waypoint *wpt, char *link, char *url_link_text) wpt->url_link_text = url_link_text; } else { url_link *tail; - url_link *new_link = (url_link*) xcalloc(sizeof(url_link), 1); + url_link *new_link = new url_link; new_link->url = link; new_link->url_link_text = url_link_text; -- 2.30.2